package com.keller.dao;

import com.keller.domian.Orders;
import com.keller.domian.Product;
import org.apache.ibatis.annotations.*;
import org.springframework.stereotype.Repository;

import java.util.List;

@Repository
public interface OrdersDao {

    @Select("select * from orders")
    @Results({
            @Result(id=true, property = "id", column = "id"),
            @Result(column = "orderNum", property = "orderNum"),
            @Result(column = "orderTime", property = "orderTime"),
            @Result(column = "orderStatus", property = "orderStatus"),
            @Result(column = "peopleCount", property = "peopleCount"),
            @Result(column = "payType", property = "payType"),
            @Result(column = "orderDesc", property = "orderDesc"),
            @Result(column = "productId", property = "product", one = @One(select = "com.keller.dao.ProductDao.findProductById"))
    })
    public List<Orders> findAll() throws Exception;

    //查询订单详情
    @Select("select * from orders where id = #{id}")
    @Results({
            @Result(id=true, property = "id", column = "id"),
            @Result(column = "orderNum",property = "orderNum"),
            @Result(column = "orderTime",property = "orderTime"),
            @Result(column = "orderStatus",property = "orderStatus"),
            @Result(column = "peopleCount",property = "peopleCount"),
            @Result(column = "payType",property = "payType"),
            @Result(column = "orderDesc",property = "orderDesc"),
            @Result(column = "productId", property = "product", one = @One(select = "com.keller.dao.ProductDao.findProductById")),
            @Result(column = "memberId", property = "member", one = @One(select = "com.keller.dao.MemberDao.findMemberById")),
            @Result(column = "id", property = "travellers", many = @Many(select = "com.keller.dao.TravellerDao.findTravellerByOrdersId"))
    })
    public Orders findOrderById(String id);
}
